﻿using Mono.Cecil;
using NETDeob.Deobfuscators.Confuser.Tasks.Common;
using NETDeob.Deobfuscators.Confuser.Tasks._1_7;
using NETDeob.Deobfuscators.Generic;
using NETDeob.Engine;
using NETDeob.Misc;
using NETDeob.Misc.Structs__Enums___Interfaces;

namespace NETDeob.Core.Deobfuscators.Confuser
{
    class ConfuserDeobfuscator : AssemblyWorker
    {
        public bool IsPacked;

        public ConfuserDeobfuscator(AssemblyDefinition asmDef) 
            : base(asmDef)
        {
        }

        public override void CreateTaskQueue()
        {
            var tmp = "";

            switch(((Signatures.ConfuserSignature)DeobfuscatorContext.ActiveSignature).InternalVersion)
            {
                case Signatures.ConfuserSignature.InternalVer.V1_7:
                    TaskQueue.Add(new ProxyResolver(AsmDef));
                    TaskQueue.Add(new MethodCleaner2(AsmDef));
                    TaskQueue.Add(new ResourceDecryptor(AsmDef));
                    TaskQueue.Add(new ConstantsDecryptor(AsmDef));
                    TaskQueue.Add(new StackUnderflowCleaner(AsmDef));
                    TaskQueue.Add(new WatermarkRemover(AsmDef));
                    TaskQueue.Add(new AntiDump(AsmDef));
                    TaskQueue.Add(new AntiDebug(AsmDef));
                    TaskQueue.Add(new AntiILDasm(AsmDef));
                    TaskQueue.Add(new AssemblyStripper(AsmDef));
                    TaskQueue.Add(new Renamer(AsmDef, new RenamingScheme(true) {Resources = false}));
                    break;

                case Signatures.ConfuserSignature.InternalVer.Unknown:

                    break;
            }

            Deobfuscate();
        }
    }
}
